package game.core
{
	/**
	 * @yinlz 2013-09-14
	 * 棋盘数据
	 */
	public class FLPan
	{
		public function FLPan()
		{
			init();
		}
		
		public var points:Array = 
			[ 
				[new FLPoint(0,0),new FLPoint(0,1),new FLPoint(0,2),new FLPoint(0,3),new FLPoint(0,4)],
				[new FLPoint(1,0),new FLPoint(1,1),new FLPoint(1,2),new FLPoint(1,3),new FLPoint(1,4)],
				[new FLPoint(2,0),new FLPoint(2,1),new FLPoint(2,2),new FLPoint(2,3),new FLPoint(2,4)],
				[new FLPoint(3,0),new FLPoint(3,1),new FLPoint(3,2),new FLPoint(3,3),new FLPoint(3,4)],
				[new FLPoint(4,0),new FLPoint(4,1),new FLPoint(4,2),new FLPoint(4,3),new FLPoint(4,4)]
			];
		
		
		public function init():void
		{
			for(var i:int =0;i<5;i++)
			{
				for(var j:int=0;j<5;j++)
				{
					var p:FLPoint = points[i][j];
					p.setFLPan(this);
				}
			}
			
			initGroup();
		}
		public function getPoint(x:int,y:int):FLPoint{
			if(x>=0&& x<5 && y>=0 && y<5)
				return points[x][y];
			return null;
		
		}
		
		public function getPointsByY(y:int):Array
		{
			var a:Array = [];
			for(var i:int =0;i<5;i++)
				a.push(getPoint(i,y));
			return a;
		}
		
		public function initGroup():void
		{
			initFang();
			this.initLiu();
			this.initSanXie();
			this.initSiBu();
			this.initWuTong();
		}
		
		public function initFang():void
		{
			var id:int = 0;
			for(var i:int=0;i<4;i++)
			{
				for(var j:int = 0;j<4;j++){
					var f:Fang = new Fang();
					var a:Array = [getPoint(i,j),getPoint(i,j+1),getPoint(i+1,j+1),getPoint(i+1,j)];
					f.id = id;
					id++;
					f.setList(a);
					groups.push(f);	
				}
			}
		}
		
		public function initLiu():void
		{
			var id:int = 0;
			for(var i:int=0;i<5;i++)
			{
				var l:Liu = new Liu();
				l.id = id;
				id++;
				l.setList(points[i]);
				groups.push(l);
			}
			for(var n:int =0;n<5;n++)
			{
				var l2:Liu = new Liu();
				l2.id = id;
				id++;
				l2.setList(getPointsByY(n));
				groups.push(l2);
			}
		}
		
		public function initSanXie():void{
			var x3:SanXie = new SanXie;
			x3.id = 0;
			x3.setList([getPoint(0,2),getPoint(1,1),getPoint(2,0)]);
			groups.push(x3);
			
			x3 = new SanXie;
			x3.id = 1;
			x3.setList([getPoint(0,2),getPoint(1,3),getPoint(2,4)]);
			groups.push(x3);
			
			x3 = new SanXie;
			x3.id = 2;
			x3.setList([getPoint(2,0),getPoint(3,1),getPoint(4,2)]);
			groups.push(x3);
			
			x3 = new SanXie;
			x3.id = 3;
			x3.setList([getPoint(4,2),getPoint(3,3),getPoint(2,4)]);
			groups.push(x3);
		}
		
		public function initSiBu():void
		{
			var b:SiBu = new SiBu;
			b.id = 0;
			b.setList([getPoint(3,0),getPoint(2,1),getPoint(1,2),getPoint(0,3)]);
			groups.push(b);
			
			b = new SiBu;
			b.id = 1;
			b.setList([getPoint(0,1),getPoint(1,2),getPoint(2,3),getPoint(3,4)]);
			groups.push(b);
			
			b = new SiBu;
			b.id = 2;
			b.setList([getPoint(1,0),getPoint(2,1),getPoint(3,2),getPoint(4,3)]);
			groups.push(b);
			
			b = new SiBu;
			b.id = 3;
			b.setList([getPoint(1,4),getPoint(2,3),getPoint(3,2),getPoint(4,1)]);
			groups.push(b);
		}
		
		
		public function initWuTong():void
		{
			var w:WuTong = new WuTong;
			w.id = 0;
			w.setList([getPoint(0,0),getPoint(1,1),getPoint(2,2),getPoint(3,3),getPoint(4,4)]);
			groups.push(w);
			
			w = new WuTong;
			w.id = 1;
			w.setList([getPoint(0,4),getPoint(1,3),getPoint(2,2),getPoint(3,1),getPoint(4,0)]);
			groups.push(w);
		}
		
		public function canPutAt(x:int,y:int,side:int):int
		{
			var p:FLPoint = getPoint(x,y);
			if(p == null)
				return 1; //  选取的点不存在
			if(side!=currSide)
				return 2; //没轮到下
			if(count<=0)
				return 3; //已经下完
			if(p.z != FLPoint.NONE)
				return 4; //不是空白点
			return 0;
		}
		
		public function putAt(x:int,y:int,side:int):Array
		{
			if(canPutAt(x,y,side)!= 0)
				return null;
			var p:FLPoint = getPoint(x,y);
			return p.onPutSide(side);
		}
		
		public var groups:Array = [];
		public var currSide:int = 0; //当前方
		public var count:int = 0; //能填几个子
	}
}